package manager;

import entity.Account;
import iface.IManager;
import java.util.ArrayList;

/**
 *
 * @author Noi
 */
public class AccountManager implements IManager<Account> {

    private ArrayList<Account> accountList;

    public AccountManager() {
        this.accountList = new ArrayList<Account>();
    }

    @Override
    public boolean add(Account obj) {
        return this.accountList.add(obj);
    }

    @Override
    public boolean remove(Account obj) {
        return this.accountList.remove(obj);
    }

    @Override
    public Account replace(int index, Account obj) {
        return this.accountList.set(index, obj);
    }

    @Override
    public Account getById(int id) {
        for(Account account: this.accountList) {
            if(Integer.valueOf(account.getAccountID()) == id)
                return account;
        }
        return null;
    }

    @Override
    public int size() {
        return this.accountList.size();
    }

    @Override
    public Account get(int index) {
        return this.accountList.get(index);
    }

    @Override
    public Account getByName(String AccountName) {
        for (Account obj : this.accountList) {
            if (obj.getAccountID().equals(AccountName)) {
                return obj;
            }
        }
        return null;
    }
    
    @Override
    public void setVisible(Account obj, boolean value) {
        for (Account object : this.accountList) {
            if (object.getAccountID().equals(obj.getAccountID())) {
                object.setStatus(value);
            }
        }
    }

    public boolean contains(String accountName) {
        for (Account block : this.accountList) {
            if (block.getAccountID().equals(accountName)) {
                return true;
            }
        }
        return false;
    }
    
    public Account checkValidate(String accountName, String password) {
        for (Account block : this.accountList) {
            if (block.getAccountID().equals(accountName) && password.equals(block.getPassword())) {
                return block;
            }
        }
        return null;
    }
}
